<?php
/**
 * @auther:周卫星
 * @date:2019/11/25
 * @fileName:add.blade.php
 * @fileDesc: 添加问题
 */
?>

@extends('admin_layout.layout')
@section('title', '添加帮助信息')

@push('css')
    <link rel="stylesheet" href="{{ Illuminate\Support\Facades\URL::asset('editor/css/editormd.min.css') }}">
    <link rel="stylesheet" href="{{ Illuminate\Support\Facades\URL::asset('editor/css/editormd.preview.min.css') }}">
@endpush
@push('js')
    {{--<script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/jquery.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/editormd.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/marked.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/prettify.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/raphael.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/underscore.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/sequence-diagram.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/flowchart.min.js') }}"></script>
    <script src="{{ Illuminate\Support\Facades\URL::asset('editor/lib/jquery.flowchart.min.js') }}"></script>--}}
    <script>
        layui.use(['table', 'element', 'form', 'layer', 'common', 'jquery'], function () {
            let $ = layui.$;
            let jquery = layui.jquery;
            let table = layui.table;
            let form = layui.form;
            let layer = layui.layer;
            let common = layui.common;

            let ue = UE.getEditor('editor');
            ue.ready(function() {
                ue.setContent("", "isAppendTo");
            });
            /*let testEditor = editormd('editormd', {
                width: '100%'
                , height: '60vh'
                , path: "/"
                , theme: 'default'
                , previewTheme: 'default'
                , editorTheme: 'default'
                , codeFold: true
                , saveHTMLToTextarea: true
                , searchReplace: true
                , htmlDecode: "style,script,iframe|on*"
                , emoji: true
                , taskList: true
                , tocm: true
                , tex: true
                , flowChart: true
                , sequenceDiagram: true
                , imageUpload: true
                , imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"]
                , imageUploadURL: ""
                , onload : function() {
                    // 加载后富文本编辑器成功后的回调
                    console.log('onload', this);
                    //this.fullscreen();
                    //this.unwatch();
                    //this.watch().fullscreen();

                    //this.setMarkdown("#PHP");
                    //this.width("100%");
                    //this.height(480);
                    //this.resize("100%", 640);

                    // 异步请求md文件，用于编辑时的数据回显
                    $.get("", function(md) {
                        testEditor.setMarkdown("请输入问题详情,在右侧可以进行实时预览,在编写详情时先删除该段文字");
                    });
                }
            })*/

            /**
             * 表格的搜索功能
             * 需要使用到数据表格的重载功能
             */
            form.on('submit(addFaq)', function (data) {
                let load = layer.load();
                // 获取问题详情
                let faq_info = ue.getContent();
                if (faq_info == '' || faq_info == '请输入问题详情,在右侧可以进行实时预览,在编写详情时先删除该段文字'){
                    common.tipMessage('帮助信息内容不能为空');
                    layer.close(load);
                    return  false;
                }else {
                    let title = data.field['title'];
                    $.ajax({
                        url: "{{ url('/faq/add-do') }}"
                        , type: 'post'
                        , data: {
                            title: title
                            , content: faq_info
                            , _token: "{{ csrf_token() }}"
                        }
                        , dataType: 'json'
                        , success: function (res) {
                            layer.close(load);
                            if (res.code === 0){
                                common.tipMessage(res.msg, 6, function () {
                                    form.val('addForm', {
                                        'title': ''
                                    });
                                    /*testEditor.setMarkdown("请输入问题详情,在右侧可以进行实时预览,在编写详情时先删除该段文字");*/
                                });
                            }else{
                                common.tipMessage(res.msg);
                            }
                        }
                        , before: function () {
                            load
                        }
                        , error: function () {
                            layer.close(load);
                        }
                    });
                }
                return false;
            });
        });
    </script>
@endpush

@section('content')
    <form class="layui-form" action="" lay-filter="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">问题详情</label>
            <div class="layui-input-block">
                <script id="editor" type="text/plain" name="content" style="width:100%;height:350px;"></script>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="addFaq">立即提交</button>
            </div>
        </div>
    </form>
@endsection
@include('UEditor::head')
